/**
* Main plugin Templates Functions File.
*
* @since 1.0
* @package Foodbakery
*/
// Direct access not allowed.
if (!defined('ABSPATH')) {
exit;
}
/**
* Templates Functions Class.
*/
class Foodbakery_Email_Templates_Functions {
/**
* Put hooks in place and activate.
*/
public function __construct() {
add_action('admin_enqueue_scripts', array($this, 'plugin_enqueue'));
add_action('foodbakery_email_template', array($this, 'jh_email_notification'), 10, 1);
add_action('send_email_with_template', array($this, 'send_email_with_template_callback'), 20, 2);
}
/*
* @ Enqueue Plugin Styles and Scripts
*/
public function plugin_enqueue() {
wp_enqueue_style('foodbakery-email-templates', FOODBAKERY_EMAIL_TEMPLATES_PLUGIN_URL . '/assets/css/foodbakery-email-templates.css');
wp_enqueue_script('foodbakery-email-templates', FOODBAKERY_EMAIL_TEMPLATES_PLUGIN_URL . '/assets/js/foodbakery-email-templates.js', array('jquery'));
}
/*
* @ Email Header
*/
private function email_header($from = '', $to = '') {
if ($from == '') {
$from = get_bloginfo('name');
}
if ($to == '') {
$to = get_bloginfo('admin_email');
}
$headers = "From: " . $from . "\r\n";
$headers .= "Reply-To: " . $to . "\r\n";
$headers .= "Content-type: text/html; charset=utf-8" . "\r\n";
$headers .= "MIME-Version: 1.0" . "\r\n";
return $headers;
}
/*
* @ Email Add New Template
*/
public function jh_email_notification($atts = array()) {
global $current_user;
$defaults = array(
'template_id' => '',
'email_from' => '',
'email_reply_to' => '',
'bcc_switch' => '',
'job_id' => '',
'user_id' => '',
'candidate_id' => '',
'from_message' => '',
'phone_number' => '',
'user_password' => '',
);
extract(shortcode_atts($defaults, $atts));
$content_template = get_post($template_id);
$content_template = $content_template->post_content;
$content_template = apply_filters('the_content', $content_template);
$content_template = str_replace(']]>', ']]>', $content_template);
$user_display_name = $current_user->display_name;
$user_email = $current_user->user_email;
if (!empty($job_id)) {
$jh_user = get_post_meta($job_id, 'foodbakery_job_username', true);
$jh_user = get_user_by('ID', $jh_user);
if (empty($jh_user)) {
$jh_user = $current_user;
}
$user_display_name = $jh_user->display_name;
$user_email = $jh_user->user_email;
}
if (!empty($user_id)) {
$jh_user = get_user_by('ID', $user_id);
$user_display_name = $jh_user->display_name;
$user_email = $jh_user->user_email;
}
$candidate_display_name = '';
if (!empty($candidate_id)) {
$jh_user = get_user_by('ID', $candidate_id);
$candidate_display_name = $jh_user->display_name;
}
$get_strings = array(
'[JOB_USER_NAME]',
'[JOB_SITE_NAME]',
'[JOB_ADMIN_EMAIL]',
'[JOB_SITE_URL]',
'[JOB_TITLE]',
'[JOB_USER_PASSWORD]',
'[JOB_CANDIDATE]',
'[JOB_FROM_NAME]',
'[JOB_REPLY_TO]',
'[JOB_PHONE_NUMBER]',
'[JOB_FROM_MESSAGE]',
);
$replace_strings = array(
$user_display_name,
get_bloginfo('name'),
get_bloginfo('admin_email'),
'' . esc_url(home_url('/')) . '',
'' . get_the_title($job_id) . '',
$user_password,
$candidate_display_name,
$email_from,
$email_reply_to,
$phone_number,
$from_message,
);
$cc_email = get_post_meta($template_id, 'jh_template_cc', true);
if ($cc_email != '' && $bcc_switch == 'on') {
$email_to = array(sanitize_email($user_email), sanitize_email($cc_email));
} else {
$email_to = sanitize_email($user_email);
}
$subject = get_post_meta($template_id, 'jh_template_subject', true);
$subject = str_replace($get_strings, $replace_strings, $subject);
$email_body = str_replace($get_strings, $replace_strings, $content_template);
$headers = Foodbakery_Email_Templates_Functions::email_header($email_from, $email_reply_to);
wp_mail($email_to, $subject, $email_body, $headers);
}
public static function send_email_with_template_callback($email_template_index, $template_type) {
$foodbakery_plugin_options = get_option('foodbakery_plugin_options');
$email_template = '';
$email_template_variables = array();
if (isset($foodbakery_plugin_options[$email_template_index])) {
$selected_template_id = intval($foodbakery_plugin_options[$email_template_index]);
// Check if a temlate selected else default template is used.
if ($selected_template_id != 0) {
$templateObj = get_post($selected_template_id);
if ($templateObj != null) {
$email_template = $templateObj->post_content;
}
} else {
if (isset(Foodbakery_Email_Templates_Post::$email_template_options)) {
if (isset(Foodbakery_Email_Templates_Post::$email_template_options['templates'][$template_type])) {
// Get default template.
$email_template = Foodbakery_Email_Templates_Post::$email_template_options['templates'][$template_type];
}
}
}
// Get Email template types in Foodbakery_Email_Templates_Post class.
if (isset(Foodbakery_Email_Templates_Post::$email_template_options)) {
$email_template_variables = array_merge(
Foodbakery_Email_Templates_Post::$email_template_options['variables']['General'], Foodbakery_Email_Templates_Post::$email_template_options['variables'][$template_type]
);
}
}
$template = self::replace_tags($email_template, $email_template_variables);
if ($email_template == null) {
$email_template = __('here is an email template' , 'foodbakery-email-templates');
}
}
public static function replace_tags($template, $variables) {
foreach ($variables as $key => $variable) {
$callback_exists = false;
// Check if function/method exists.
if (is_array($variable['value_callback'])) { // If it is a method of a class.
$callback_exists = method_exists($variable['value_callback'][0], $variable['value_callback'][1]);
} else { // If it is a function.
$callback_exists = function_exists($variable['value_callback']);
}
// Substitute values in place of tags if callback exists.
if (true == $callback_exists) {
// Make a call to callback to get value.
$value = call_user_func($variable['value_callback']);
// If we have some value to substitute then use that.
if (false != $value) {
$template = str_replace('[' . $variable['tag'] . ']', $value, $template);
}
}
}
return $template;
}
}
$foodbakery_email_functions = new Foodbakery_Email_Templates_Functions();// https://github.com/twbs/bootstrap-sass/blob/3.3-stable/assets/stylesheets/bootstrap/mixins/_gradients.scss#L17-L27
// Vertical gradient, from top to bottom
//
// Creates two color stops, start and end, by specifying a color and position for each color stop.
// Color stops are not available in IE9 and below.
@mixin gradient-vertical($start-color: #555, $end-color: #333, $start-percent: 0%, $end-percent: 100%) {
background-image: -webkit-linear-gradient(top, $start-color $start-percent, $end-color $end-percent); // Safari 5.1-6, Chrome 10+
background-image: -o-linear-gradient(top, $start-color $start-percent, $end-color $end-percent); // Opera 12
background-image: linear-gradient(to bottom, $start-color $start-percent, $end-color $end-percent); // Standard, IE10, Firefox 16+, Opera 12.10+, Safari 7+, Chrome 26+
background-repeat: repeat-x;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#{ie-hex-str($start-color)}', endColorstr='#{ie-hex-str($end-color)}', GradientType=0); // IE9 and down
}
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DownloadsMenu=void 0;const components_1=require("@wordpress/components"),element_1=require("@wordpress/element"),i18n_1=require("@wordpress/i18n"),icons_1=require("@wordpress/icons"),insert_url_menu_item_1=require("../insert-url-menu-item"),upload_files_menu_item_1=require("../upload-files-menu-item");function DownloadsMenu({allowedTypes:e,maxUploadFileSize:n,onUploadSuccess:o,onUploadError:r}){return(0,element_1.createElement)(components_1.Dropdown,{popoverProps:{placement:"bottom-end"},contentClassName:"woocommerce-downloads-menu__menu-content",renderToggle:({isOpen:e,onToggle:n})=>(0,element_1.createElement)(components_1.Button,{"aria-expanded":e,icon:e?icons_1.chevronUp:icons_1.chevronDown,variant:"secondary",onClick:n,className:"woocommerce-downloads-menu__toogle"},(0,element_1.createElement)("span",null,(0,i18n_1.__)("Add new","woocommerce"))),renderContent:({onClose:t})=>(0,element_1.createElement)("div",{className:"components-dropdown-menu__menu"},(0,element_1.createElement)(components_1.MenuGroup,null,(0,element_1.createElement)(upload_files_menu_item_1.UploadFilesMenuItem,{allowedTypes:e,maxUploadFileSize:n,onUploadSuccess:e=>{o(e),t()},onUploadError:r}),(0,element_1.createElement)(insert_url_menu_item_1.InsertUrlMenuItem,{onUploadSuccess:e=>{o(e),t()},onUploadError:r})))})}exports.DownloadsMenu=DownloadsMenu;